﻿using System;
using MosCraft.Utilities;

namespace MosCraft.Terrain.WorldGen
{
    class WorldGenReed : WorldGenerator
    {
        public WorldGenReed()
        {
        }

        override public bool generate(World world, FastRandom random, int x, int y, int z)
        {
            for (int i = 0; i < 3; i++)
            {
                int randIntX = (x + random.nextInt(4)) - random.nextInt(4);
                int randIntY = y;
                int randIntZ = (z + random.nextInt(4)) - random.nextInt(4);

                //Console.WriteLine("{0} {1} {2}", randIntX, randIntY, randIntZ);

                if (world.getBlockMaterial(randIntX, randIntY - 1, randIntZ) == Material.Water)
                {
                    continue;
                }

                int maxHeight = 2 + random.nextInt(random.nextInt(3) + 1);

                for (int j = 0; j < maxHeight; j++)
                {
                    if (Block.Reeds.canBlockStay(world, randIntX, randIntY + j, randIntZ))
                    {
                        world.setBlockID(randIntX, randIntY + j, randIntZ, Block.Reeds.blockID);
                    }
                }

            }

            return true;
        }
    }
}
